﻿#include "ssLog.h"
#ifdef _WIN32
#include <windows.h>
#include <direct.h>
#else
#include <sys/stat.h>
#endif
#include "../time/ssTime.h"


namespace StarSeeker
{

ssLog::ssLog()
{

}

ssLog::ssLog(u8 type, const char* path)
	:ssLogBase(type, path), m_buffer(LOG_STR_LEN)
{
}

ssLog::~ssLog()
{
}

void ssLog::OutPut(SS_LOG_TYPE type, const char *pLogString)
{
	ssLogBase::OutPut2Buffer(type, pLogString, m_buffer);
	PrintBuffer(type);
}

void ssLog::OutPutEx(SS_LOG_TYPE type, const char *pLogString, ...)
{
	va_list arglist;
	va_start(arglist, pLogString);
	ssLogBase::OutPutEx2Buffer(type, pLogString, arglist, m_buffer);
	va_end(arglist);
	PrintBuffer(type);
}

void ssLog::PrintDebug(const char *pLogString)
{
	OutPut(SS_LOG_TYPE::LOG_DEBUG, pLogString);
}

void ssLog::PrintDebugEx(const char *pLogString, ...)
{
	va_list arglist;
	va_start(arglist, pLogString);
	ssLogBase::OutPutEx2Buffer(SS_LOG_TYPE::LOG_DEBUG, pLogString, arglist, m_buffer);
	va_end(arglist);
	PrintBuffer(SS_LOG_TYPE::LOG_DEBUG);
}

void ssLog::Print(const char *pLogString)
{
	OutPut(SS_LOG_TYPE::LOG_INFO, pLogString);
}

void ssLog::PrintEx(const char *pLogString, ...)
{
	va_list arglist;
	va_start(arglist, pLogString);
	ssLogBase::OutPutEx2Buffer(SS_LOG_TYPE::LOG_INFO, pLogString, arglist, m_buffer);
	va_end(arglist);
	PrintBuffer(SS_LOG_TYPE::LOG_INFO);
}

void ssLog::Error(const char *pLogString)
{
	OutPut(SS_LOG_TYPE::LOG_ERROR, pLogString);
}

void ssLog::ErrorEx(const char *pLogString, ...)
{
	va_list arglist;
	va_start(arglist, pLogString);
	ssLogBase::OutPutEx2Buffer(SS_LOG_TYPE::LOG_ERROR, pLogString, arglist, m_buffer);
	va_end(arglist);
	PrintBuffer(SS_LOG_TYPE::LOG_ERROR);
}

void ssLog::PrintFile(const char *pLogString)
{
	OutPut(SS_LOG_TYPE::LOG_FILE_ONLY, pLogString);
}

void ssLog::PrintFileEx(const char *pLogString, ...)
{
	va_list arglist;
	va_start(arglist, pLogString);
	ssLogBase::OutPutEx2Buffer(SS_LOG_TYPE::LOG_FILE_ONLY, pLogString, arglist, m_buffer);
	va_end(arglist);
	PrintBuffer(SS_LOG_TYPE::LOG_FILE_ONLY);
}

void ssLog::PrintBuffer(SS_LOG_TYPE type)
{
	if ((m_printFlag&type) && !(type&LOG_FILE_ONLY))
	{
//#ifdef _WIN32
//	::OutputDebugStringA(m_buffer.GetString());
//#endif
		std::cout << m_buffer.GetString() << std::endl;
	}
	if ((m_fileFlag&type) || (type&LOG_FILE_ONLY))
	{
		SaveToFile(m_buffer.GetString());
	}
}

}
